package demo1;

import java.util.Arrays;

public class Test {
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5};
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main(String[] args) {
        Student[] array = new Student[3];
        array[0] = new Student("xue",19,90);
        array[1] = new Student("yue",9,80);
        array[2] = new Student("huang",8,10);
        System.out.println("排序前: "+ Arrays.toString(array));
        /*Arrays.sort(array);//没有告诉编译器通过哪个对象排序？？？*/
        System.out.println("排序后: "+ Arrays.toString(array));
    }

    public static void main3(String[] args) {
        Student student1 = new Student("huang",19,20);
        Student student2 = new Student("xue",20,80);
        int ret = student1.compareTo(student2);
        System.out.println(ret);
    }

}

class Student implements Comparable<Student>{
    public String name;
    public int age;
    public double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }


    @Override
    public int compareTo(Student o) {
        /*if(this.age - o.age >0){
            return 1;
        }else if(this.age - o.age < 0){
            return 0;
        }else {
            return -1;
        }*/
        return this.age - o.age;
    }
}
